package com.mju.controller.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

// 封装结果，控制层的每个方法，都返回此类的对象
@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult<E> implements Serializable {

    private Integer status; // 状态码
    private String message; // 描述信息
    private E data; // 响应的数据
    private String token; // 传递给前端的token
    //将状态码传给构造方法初始化对象
    public JsonResult(Integer status) {
        this.status = status;
    }

//    public JsonResult(Integer status, String token) {
//        this.status = status;
//        this.token = token;
//    }

    //消息和状态码封装
    public JsonResult(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    //将状态码和数据传给构造方法初始化对象
    public JsonResult(Integer status, E data) {
        this.status = status;
        this.data = data;
    }
    public JsonResult(Integer status, E data, String token) {
        this.status = status;
        this.data = data;
        this.token = token;
    }

    //如果有异常,直接将异常传递给构造方法初始化对象
    public JsonResult(Throwable e) {
        this.message=e.getMessage();
    }



}
